<template>
  <div id="app" v-show="isShow">

    <!--<keep-alive>-->
      <router-view v-if="isRouterAlive" />
    <!--</keep-alive>-->
  </div>
</template>

<script>
  import {mapState,mapMutations,mapGetters} from 'vuex';


  export default {
    name: 'App',
    data(){
      return {
        isShow:false,
        isRouterAlive: true
      }
    },
    provide(){
      return {
        reload: this.reload
      }
    },
    computed: {
      ...mapState(['tabIcon',"tabIconBusiness"]),
      ...mapMutations(['getScreenHeight']),
      ...mapGetters(['collectUserInfo'])
    },
    created() {
      this.$store.commit('getScreenHeight',($(document).height())/100);
      this.$store.commit('obtainUserInfo',this.$myStorage.query());
    },
    beforeCreate() {
      if (this.$myStorage.getItem(1,'VerificationCodeTime')) {

      }else {
        this.$myStorage.setItem('localStorage','VerificationCodeTime','获取验证码')
      }
      // this.$toast('加载中');
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
      });
      this.$nextTick(()=>{
        this.$toast.clear();
        this.isShow = true;
      });
    },
    watch: {
      //用户端
      $route(to, from) {
        switch (to.path.replace('/views/', '')) {
          case 'Business/Index':
            this.$store.commit('tabIconBusiness',[true,false,false]);
            break;
          case 'Business/order':
            this.$store.commit('tabIconBusiness',[false,true,false]);
            break;
          case 'Business/my':
            this.$store.commit('tabIconBusiness',[false,false,true]);
            break;
          case 'Client/index':
            this.$store.commit('tabIcon', [true, false]);
            break;
          case 'Client/my':
            this.$store.commit('tabIcon', [false, true]);
            break;
          default:
            this.$store.commit('tabIcon', [false, false]);
            this.$store.commit('tabIconBusiness', [true, false,false]);
            break;
        }
      }
    },
    methods: {
      reload(){
        this.isRouterAlive = false;
        this.$nextTick(function () {
          this.isRouterAlive = true
        })
      }
    }
  }
</script>

<style>

  /* 加载遮罩 */
  .el-loading-spinner {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    min-height: 5.87rem;
    margin: 0;
    box-sizing: border-box;
    padding: 1.5rem 0;
    background-color: rgba(0, 0, 0, .6);
  }

  /deep/ .van-image-preview__index {
    top: .1rem !important;
    color: #fff;
    font-size: .14rem;
    text-shadow: 0 .01rem .01rem #323233;
  }
</style>
